<template>
	<el-input
		v-model="val"
		:placeholder="tip"
		size="small"
		prefix-icon="el-icon-search"
		@keyup.native="echo($event)"
		onkeyup="this.value=this.value.replace(/[^A-Za-z0-9\u4E00-\u9FA5]/g, '');">
	</el-input>
</template>

<script>
export default {
	props:["tip"],
	data () {
		return {
			val:"",
			timer:"",
		}
	},
	watch:{
		//清空的时候
		val:function(x){
			if(x == ''){
				this.$emit("searchOK",'');
			}
		}
	},
	methods:{
		echo:function(e){
			if(this.val == this.regular(this.val) || this.val == ''){
				clearTimeout(this.timer);
				this.timer = setTimeout(()=>{
					console.log(this.val)
					this.$emit("searchOK",this.regular(this.val))
				}, 500)
			}
		},
		//不能输入特殊符号
		regular:function(value){
			return value.replace(/[^A-Za-z0-9\u4E00-\u9FA5]/g, '');
		}
	}
}
</script>

<style lang="scss" scoped>

</style>
